/*
day95
2019.12.1
*/
#include<vector>
#include<stdlib.h>
using namespace std;

struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) : val(x), left(NULL), right(NULL) {};
};

class Solution {
public:
	TreeNode *help(vector<int>& nums,int begin,int end)
	{
		if(begin>end) return NULL;
		int max=nums[begin];
		int index=begin;
		for(int i=begin;i<=end;i++)
		{
			if(nums[i]>max)
			{
				max=nums[i];
				index=i;
			} 
		}
		TreeNode *root=new TreeNode(max);
		root->left=help(nums,begin,index-1);
		root->right=help(nums,index+1,end);
		return root;
	}
	
    TreeNode* constructMaximumBinaryTree(vector<int>& nums) {
        return help(nums,0,nums.size()-1);
    }
};

int main()
{
	
	return 0;
}
